﻿using System.Collections.Generic;
using System.Runtime.Serialization;
using Foundation.Markup;
using Vent.Resources;
using ViewModel = Foundation.ViewModel;

namespace Vent.ViewModels
{
    [DataContract]
    public class SettingsViewModel : ViewModel
    {
        public SettingsViewModel()
        {
            Initialize();
        }

        [DataMember]
        public string Language
        {
            get { return Get(() => Language, "English"); }
            set { Set(() => Language, value); }
        }

        public List<string> Languages { get; set; }

        [OnDeserialized]
        public new void Initialize(StreamingContext context = default(StreamingContext))
        {
            Languages = new List<string> {"English", "Russian"};
            SetLanguage(Language);
            this[() => Language].PropertyChanged += (sender, args) => SetLanguage(Language);
        }

        private void SetLanguage(string name)
        {
            switch (name)
            {
                case "English":
                    Localizing.Manager.Source = English.ResourceManager;
                    break;
            }
            switch (Language)
            {
                case "Russian":
                    Localizing.Manager.Source = Russian.ResourceManager;
                    break;
            }
        }
    }
}